import tkinter as tk
from tkinter import ttk  # 导入 ttk 模块，用于改进控件的外观


class MyApp:
    def __init__(self, root):
        self.root = root
        self.root.title("优化后的界面")

        # 设置整体的背景色和边距
        self.root.configure(background="#2B2B2B")
        self.root.geometry("400x400")

        # 创建顶部面板
        self.create_top_panel()

        # 创建中上面板
        self.create_middle_top_panel()

        # 创建中下面板
        self.create_middle_bottom_panel()

        # 创建底部日志框
        self.create_bottom_log_panel()

    def create_top_panel(self):
        top_panel = tk.Frame(self.root, bg="#2B2B2B", padx=10, pady=10)
        top_panel.grid(row=0, column=0, columnspan=3, sticky="ew")

        # 操作标签
        label_operation = tk.Label(top_panel, text="操作:", font=("Helvetica", 12), bg="#2B2B2B", fg="white")
        label_operation.grid(row=0, column=0, padx=(0, 10), pady=5, sticky="e")

        # 选择框
        choices = ["Option 1", "Option 2", "Option 3"]
        self.choice_var = tk.StringVar()
        self.choice_var.set(choices[0])
        select_box = ttk.Combobox(top_panel, textvariable=self.choice_var, values=choices, state="readonly", width=15)
        select_box.grid(row=0, column=1, padx=10, pady=5, sticky="w")  # 调整选择框的对齐方式为左对齐

        # 状态图标（示例）
        status_icon = tk.Label(top_panel, text="✔", font=("Helvetica", 16), bg="#2B2B2B", fg="white")
        status_icon.grid(row=0, column=2, padx=10, pady=5)

    def create_middle_top_panel(self):
        middle_top_panel = tk.Frame(self.root, bg="#2B2B2B", padx=10, pady=10)
        middle_top_panel.grid(row=1, column=0, columnspan=3, sticky="ew")

        # 参数1标签
        label_param1 = tk.Label(middle_top_panel, text="参数1:", font=("Helvetica", 12), bg="#2B2B2B", fg="white")
        label_param1.grid(row=0, column=0, padx=(0, 10), pady=5, sticky="e")

        # 输入框
        entry_param1 = tk.Entry(middle_top_panel, width=30)
        entry_param1.grid(row=0, column=1, padx=10, pady=5, sticky="w")  # 调整输入框的对齐方式为左对齐

    def create_middle_bottom_panel(self):
        middle_bottom_panel = tk.Frame(self.root, bg="#2B2B2B", padx=10, pady=10)
        middle_bottom_panel.grid(row=2, column=0, columnspan=3, sticky="ew")

        # 确认按钮
        button_confirm = tk.Button(middle_bottom_panel, text="确认", bg="#4CAF50", fg="white", font=("Helvetica", 12),
                                   width=10)
        button_confirm.grid(row=0, column=0, padx=5, pady=5)

        # 清空按钮
        button_clear = tk.Button(middle_bottom_panel, text="清空", bg="#FF5733", fg="white", font=("Helvetica", 12),
                                 width=10)
        button_clear.grid(row=0, column=1, padx=5, pady=5)

    def create_bottom_log_panel(self):
        bottom_panel = tk.Frame(self.root, bg="#2B2B2B", padx=10, pady=10)
        bottom_panel.grid(row=3, column=0, columnspan=3, sticky="nsew")

        # 日志框
        log_text = tk.Text(bottom_panel, height=10, width=50, font=("Helvetica", 10), bg="#3B3B3B", fg="white")
        log_text.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")

        # 添加滚动条
        scrollbar = tk.Scrollbar(bottom_panel, command=log_text.yview)
        scrollbar.grid(row=0, column=1, sticky='nsew')
        log_text.config(yscrollcommand=scrollbar.set)

        # 模拟一些日志内容
        for i in range(20):
            log_text.insert(tk.END, f"This is log entry {i}\n")

        # 设置日志框只读
        log_text.config(state=tk.DISABLED)


if __name__ == "__main__":
    root = tk.Tk()
    app = MyApp(root)
    root.mainloop()
